<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商城设置</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" media="all">
    <style>
        .setting-container {
            padding: 20px;
        }

        .setting-container input {
            width: 60px;
            text-align: center;
            padding-left: 0;
        }

        .setting-container .layui-inline {
            display: flex;
            align-items: center;
        }
        .layui-card{
            border: 1px solid #eee;
        }
        .divs span{
            padding-left: 20px;
        }
    </style>
</head>

<body>
<div class="setting-container">

    <!-- 搜索 -->
    <div class="searchInput">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>交易设置</legend>
        </fieldset>
        <form class="layui-form" action="" lay-filter="resets">
            <div class="layui-card divs">
                <div class="layui-card-header">交易设置</div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <span style="color:red; font-size:16px;">* </span>待付款订单取消时间：<input class="layui-input" name="orderCancelTime" placeholder="输入分钟数" autocomplete="off"> &nbsp;&nbsp; 分钟内未付款，自动取消订单
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <span style="color:red; font-size:16px;">* </span>订单自动确认时间：<input class="layui-input" name="orderAutoArrival" placeholder="天数" autocomplete="off"> &nbsp;&nbsp; 天，自动确认到货
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <span style="color:red; font-size:16px;">* </span>当商品的库存数量少于： <input class="layui-input" lay-verify="required|number" lay-reqtext="库存数不能为空，并且必须为数字" name="kuCunLimit" placeholder="库存数" autocomplete="off"> &nbsp;&nbsp; 件时，提示补充库存
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="padding: 0; width: auto; line-height: 37px;"><span style="color:red; font-size:16px;">* </span>分销消费门槛：</label>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" style="width: 300px;text-align: left;padding: 10px;" name="buyLimit" lay-verify="required|number" lay-reqtext="购买消费限制是必填项，岂能为空？" placeholder="请输入购买消费限制" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">元</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="padding: 0; width: auto; line-height: 37px;"><span style="color:red; font-size:16px;">* </span>提现手续费费率配置：</label>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" style="width: 260px;text-align: left;padding: 10px;" max="3" min="1" name="cashOutRate" lay-verify="required|number" lay-reqtext="不能为空" placeholder="请输入提现手续费费率" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">%</div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <span style="color:red; font-size:16px;">* </span>商品退换货地址：<textarea style="width: 300px;" placeholder="请输入商品退换货地址" name="returnAddress" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <span style="color:red; font-size:16px;margin-left:40px;">* </span>提现规则：<textarea style="width: 300px;" placeholder="请输入提现规则" name="withdrawalRules" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="padding: 0; width: auto; line-height: 37px;"><span style="color:red; font-size:16px;">* </span>大额提现配置：</label>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" style="width: 260px;text-align: left;padding: 10px;" max="3" min="1" name="cashOutLimit" lay-verify="required|number" lay-reqtext="不能为空" placeholder="请输入大额提现限制" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">元</div>
                    </div>
                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label" style="padding-left:0;width: 124px;"><span style="color:red; font-size:16px;">* </span>分销订单支付方式</label>
                        <div class="layui-input-block" id='payList'>
                        </div>
                    </div>
            </div>
            <input type="hidden" name="confType">
            <input type="hidden" name="confId">

            <fieldset class="layui-elem-field layui-field-title">
                <legend>消费设置</legend>
            </fieldset>
            <div class="layui-card">
                <div class="layui-card-header">消费设置</div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>优先条件:</label>
                    <div class="layui-input-block" style="margin-top: 10px;">
                        <!-- 1、消费满           积分，返现金         元，返          积分，（只限于中级、高级）后台能够设置 -->
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            消费满 
                        </div>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" required  name="payIntegralLimit" lay-verify="required|number" lay-reqtext="积分不能为空，并且必须为数字" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            积分，返现金
                        </div>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" required  name="returnMoney" lay-verify="required|number" lay-reqtext="现金数不能为空，并且必须为数字" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            元，返
                        </div>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text" required  name="returnIntegral" lay-verify="required|number" lay-reqtext="积分不能为空，并且必须为数字" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            积分，（只限于中级、高级）
                        </div>
                    </div>
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title">
                <legend>营销设置</legend>
            </fieldset>
            <div class="layui-card">
                <div class="layui-card-header">优先排队设置</div>
                <div class="layui-form-item">
                    <label class="layui-form-label">适用人群:</label>
                    <div class="layui-input-block" style="line-height: 39px;">
                        分销会员
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>优先条件:</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            个人两级分销内，每满
                        </div>
                        <div class="layui-input-inline" style="width:auto;">
                            <input type="text"  required lay-verify="required" name="distributionUpgradeLimt" lay-verify="required|number" lay-reqtext="优先条件不能为空？" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width:auto;line-height: 39px;">
                            个订单，可以享受优先插队
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-card">
                <div class="layui-card-header">商品佣金设置</div>
                <div class="layui-form-item">
                    <label class="layui-form-label">适用人群:</label>
                    <div class="layui-input-block" style="line-height: 39px;">
                        VIP会员 分销会员
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom: 0px;">
                    <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>第一次商品佣金比例:</label>
                    <div class="layui-input-inline"  style="width:auto;">
                        <input type="text" name="goodsRewordRate" required lay-verify="required" lay-verify="required|number"  lay-reqtext="优先条件不能为空？" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">%</div>
                </div>
                <div style="padding-left: 105px;margin-bottom: 15px;">被推荐人购买商品的价格的 %，作为推荐人的收益</div>
                <div class="layui-form-item" style="margin-bottom: 0px;">
                    <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>佣金比例:</label>
                    <div class="layui-input-inline"  style="width:auto;">
                        <input type="text" name="goodsRewordRateOther" required lay-verify="required" lay-verify="required|number"  lay-reqtext="优先条件不能为空？" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">%</div>
                </div>
                <div style="padding-left: 105px;margin-bottom: 15px;">被推荐人购买商品的价格的 %，作为推荐人的收益</div>
                <div class="layui-form-item" style="margin-bottom: 0px;">
                    <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>购物折扣:</label>
                    <div class="layui-input-inline"  style="width:auto;">
                        <input type="text" name="goodsDiscountRate" required lay-verify="required" lay-verify="required|number" lay-reqtext="优先条件不能为空？" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">折</div>
                </div>
                <div style="padding-left: 105px;margin-bottom: 15px;">会员购买商品折扣</div>
            </div>

            <button class="layui-btn" data-type="reload" lay-submit="" lay-filter="saveForm">保存</button>
        </form>
    </div>

</div>

</body>

<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.all.min.js"></script>
<script src="../utils.js"></script>
<script>
    var checkedArr = [];
    layui.use(['form', 'jquery'], function() {
        var form = layui.form,
            $ = layui.jquery;

        ajax({
            path: "/order/getSysOrderConf",
            type: "GET",
            success: function(res) {
                var html = '';
                res.payModeList.map((item, index) => {
                    if(item.payModeSelected == 1) {
                    checkedArr[item.payModeInt]=item.payModeInt;
                }
                html += '<input type="checkbox" lay-filter="payType" value="' + item.payModeInt + '" name="pay_' + item.payModeInt + '" lay-skin="primary" title="' + item.payModeName + '"';
                if(item.payModeSelected == 1){
                    html += '" checked="';
                }
                html += '">';

            })
                $("#payList").append(html);

                res.payIntegralLimit = res.jiFenReturnConfig.payIntegralLimit;
                res.returnIntegral = res.jiFenReturnConfig.returnIntegral;
                res.returnMoney = res.jiFenReturnConfig.returnMoney;

                form.val("resets", res)
            }
        }, $)
        form.on("checkbox(payType)", function(e) {
            console.log(e.elem.value);
            console.log($(e.elem).prop('checked'));
            if($(e.elem).prop('checked')){
                checkedArr[e.elem.value]=e.elem.value;
            }else{
                checkedArr[e.elem.value]=0;
            }
        })
        // 搜索
        form.on("submit(saveForm)", function(e) {
            var payModes = '';
            var first = 0;
            if(checkedArr[1] && checkedArr[1] == 1){
                if(first == 1){
                    payModes = payModes+",1";
                }else{
                    payModes = payModes+"1";
                    first = 1;
                }

            }
            if(checkedArr[2] && checkedArr[2] == 2){
                if(first == 1){
                    payModes = payModes+",2";
                }else{
                    payModes = payModes+"2";
                    first = 1;
                }
            }
            if(checkedArr[5] && checkedArr[5] == 5){
                if(first == 1){
                    payModes = payModes+",5";
                }else{
                    payModes = payModes+"5";
                    first = 1;
                }
            }
            if(checkedArr[6] && checkedArr[6] == 6){
                if(first == 1){
                    payModes = payModes+",6";
                }else{
                    payModes = payModes+"6";
                    first = 1;
                }
            }

            if(checkedArr[7] && checkedArr[7] == 7){
                if(first == 1){
                    payModes = payModes+",7";
                }else{
                    payModes = payModes+"7";
                    first = 1;
                }
            }
            e.field.payModes = payModes;
            console.log(e.field.payModes);
            if(e.field.payModes.length == 0) {
                layer.msg("最少选择一种支付方式")
                return false;
            }
            if(e.field.cashOutRate < 0 || e.field.cashOutRate > 100) {
                layer.msg("提现费率取值范围在0-100之间")
                return false;
            }

            if(e.field.goodsRewordRate < 0 || e.field.goodsRewordRate > 100) {
                layer.msg("第一次商品佣金取值范围在0-100之间")
                return false;
            }
            if(e.field.goodsRewordRateOther < 0 || e.field.goodsRewordRateOther > 100) {
                layer.msg("商品拥挤取值范围在0-100之间")
                return false;
            }
            if(e.field.goodsDiscountRate < 0 || e.field.goodsDiscountRate > 10) {
                layer.msg("会员购买折扣取值范围在0-10之间")
                return false;
            }

            e.field.jiFenReturnConfig = {
                payIntegralLimit: e.field.payIntegralLimit,
                returnIntegral: e.field.returnIntegral,
                returnMoney: e.field.returnMoney
            }

            ajax({
                path: "/order/createOrUpdateSysOrderConf",
                type: "POST",
                data: e.field,
                success: function(res) {
                    layer.msg("更新成功！")
                }
            }, $)

            return false;
        })
    });
</script>

</html>